import request from '@/utils/request'

const api_name = "/admin/system/sysRole"   //ES6常量命名方式

  /*
  获取角色分页列表(带搜索)
  */
export default {        
    getPageList(page,limit,roleQueryVo){
        return request({
            //后端接口路径
            // url: '/admin/system/sysRole/'+page+'/'+limit,
            //使用ES6的模板字符串来进行拼接后端接口路径
            url:`${api_name}/${page}/${limit}`, 
            method: 'get',      //请求方式
            params: roleQueryVo //参数
          })
    },
//删除
    DeleteRole(id){
      return request({
        url:`${api_name}/${id}`, 
        method: 'delete',      //请求方式
      })
    },
//查询单个
    SelectByID(id){
      return request({
        url:`${api_name}/${id}`, 
        method: 'get',
      })
    },
//更新
    Updata(role){
      return request({
        url:`${api_name}`, 
        method: 'put',
        data: role
      })
    },
//添加
    Add(role){
      return request({
        url:`${api_name}`, 
        method: 'post',
        data: role
      })
    },
//批量删除
    DeleteByIds(idList){
      return request({
        url: `${api_name}/batchRemove`,
        method: `delete`,
        data: idList
      })
    },

    //根据用户id查询用户已分配的角色
    getRolesByUserId(userId) {
      return request({
        url: `${api_name}/toAssign/${userId}`,
        method: 'get'
      })
    },

    //分配角色
    assignRoles(assginRoleVo) {
      return request({
        url: `${api_name}/doAssign`,
        method: 'post',
        data: assginRoleVo
      })
    }
}
